// $ANTLR 3.4 D:\\work\\antlr\\SimpleCalc.g 2012-04-08 21:21:44
package com.antlr.sample;

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class SimpleCalcParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DIGIT", "DIV", "MINUS", "MULT", "NUMBER", "PLUS", "WHITESPACE", "';'"
    };

    public static final int EOF=-1;
    public static final int T__11=11;
    public static final int DIGIT=4;
    public static final int DIV=5;
    public static final int MINUS=6;
    public static final int MULT=7;
    public static final int NUMBER=8;
    public static final int PLUS=9;
    public static final int WHITESPACE=10;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public SimpleCalcParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public SimpleCalcParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return SimpleCalcParser.tokenNames; }
    public String getGrammarFileName() { return "D:\\work\\antlr\\SimpleCalc.g"; }


        public static void main(String[] args) throws Exception {
            SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream(args[0]));
            CommonTokenStream tokens = new CommonTokenStream(lex);
     
            SimpleCalcParser parser = new SimpleCalcParser(tokens);
     
            try {
                parser.expr();
            } catch (RecognitionException e)  {
                e.printStackTrace();
            }
        }


    public static class statments_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "statments"
    // D:\\work\\antlr\\SimpleCalc.g:30:1: statments : expr ';' !;
    public final SimpleCalcParser.statments_return statments() throws RecognitionException {
        SimpleCalcParser.statments_return retval = new SimpleCalcParser.statments_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token char_literal2=null;
        SimpleCalcParser.expr_return expr1 =null;


        Object char_literal2_tree=null;

        try {
            // D:\\work\\antlr\\SimpleCalc.g:30:11: ( expr ';' !)
            // D:\\work\\antlr\\SimpleCalc.g:31:5: expr ';' !
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_expr_in_statments95);
            expr1=expr();

            state._fsp--;

            adaptor.addChild(root_0, expr1.getTree());

            char_literal2=(Token)match(input,11,FOLLOW_11_in_statments97); 

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "statments"


    public static class expr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr"
    // D:\\work\\antlr\\SimpleCalc.g:34:1: expr : term ( ( PLUS | MINUS ) term )* ;
    public final SimpleCalcParser.expr_return expr() throws RecognitionException {
        SimpleCalcParser.expr_return retval = new SimpleCalcParser.expr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token set4=null;
        SimpleCalcParser.term_return term3 =null;

        SimpleCalcParser.term_return term5 =null;


        Object set4_tree=null;

        try {
            // D:\\work\\antlr\\SimpleCalc.g:34:9: ( term ( ( PLUS | MINUS ) term )* )
            // D:\\work\\antlr\\SimpleCalc.g:34:11: term ( ( PLUS | MINUS ) term )*
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_term_in_expr114);
            term3=term();

            state._fsp--;

            adaptor.addChild(root_0, term3.getTree());

            // D:\\work\\antlr\\SimpleCalc.g:34:16: ( ( PLUS | MINUS ) term )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==MINUS||LA1_0==PLUS) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // D:\\work\\antlr\\SimpleCalc.g:34:18: ( PLUS | MINUS ) term
            	    {
            	    set4=(Token)input.LT(1);

            	    if ( input.LA(1)==MINUS||input.LA(1)==PLUS ) {
            	        input.consume();
            	        adaptor.addChild(root_0, 
            	        (Object)adaptor.create(set4)
            	        );
            	        state.errorRecovery=false;
            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        throw mse;
            	    }


            	    pushFollow(FOLLOW_term_in_expr129);
            	    term5=term();

            	    state._fsp--;

            	    adaptor.addChild(root_0, term5.getTree());

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "expr"


    public static class term_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "term"
    // D:\\work\\antlr\\SimpleCalc.g:36:1: term : factor ( ( MULT | DIV ) factor )* ;
    public final SimpleCalcParser.term_return term() throws RecognitionException {
        SimpleCalcParser.term_return retval = new SimpleCalcParser.term_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token set7=null;
        SimpleCalcParser.factor_return factor6 =null;

        SimpleCalcParser.factor_return factor8 =null;


        Object set7_tree=null;

        try {
            // D:\\work\\antlr\\SimpleCalc.g:36:9: ( factor ( ( MULT | DIV ) factor )* )
            // D:\\work\\antlr\\SimpleCalc.g:36:11: factor ( ( MULT | DIV ) factor )*
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_factor_in_term145);
            factor6=factor();

            state._fsp--;

            adaptor.addChild(root_0, factor6.getTree());

            // D:\\work\\antlr\\SimpleCalc.g:36:18: ( ( MULT | DIV ) factor )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==DIV||LA2_0==MULT) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // D:\\work\\antlr\\SimpleCalc.g:36:20: ( MULT | DIV ) factor
            	    {
            	    set7=(Token)input.LT(1);

            	    if ( input.LA(1)==DIV||input.LA(1)==MULT ) {
            	        input.consume();
            	        adaptor.addChild(root_0, 
            	        (Object)adaptor.create(set7)
            	        );
            	        state.errorRecovery=false;
            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        throw mse;
            	    }


            	    pushFollow(FOLLOW_factor_in_term159);
            	    factor8=factor();

            	    state._fsp--;

            	    adaptor.addChild(root_0, factor8.getTree());

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "term"


    public static class factor_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "factor"
    // D:\\work\\antlr\\SimpleCalc.g:38:1: factor : NUMBER ;
    public final SimpleCalcParser.factor_return factor() throws RecognitionException {
        SimpleCalcParser.factor_return retval = new SimpleCalcParser.factor_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token NUMBER9=null;

        Object NUMBER9_tree=null;

        try {
            // D:\\work\\antlr\\SimpleCalc.g:38:9: ( NUMBER )
            // D:\\work\\antlr\\SimpleCalc.g:38:11: NUMBER
            {
            root_0 = (Object)adaptor.nil();


            NUMBER9=(Token)match(input,NUMBER,FOLLOW_NUMBER_in_factor173); 
            NUMBER9_tree = 
            (Object)adaptor.create(NUMBER9)
            ;
            adaptor.addChild(root_0, NUMBER9_tree);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "factor"

    // Delegated rules


 

    public static final BitSet FOLLOW_expr_in_statments95 = new BitSet(new long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_11_in_statments97 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_term_in_expr114 = new BitSet(new long[]{0x0000000000000242L});
    public static final BitSet FOLLOW_set_in_expr118 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_term_in_expr129 = new BitSet(new long[]{0x0000000000000242L});
    public static final BitSet FOLLOW_factor_in_term145 = new BitSet(new long[]{0x00000000000000A2L});
    public static final BitSet FOLLOW_set_in_term149 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_factor_in_term159 = new BitSet(new long[]{0x00000000000000A2L});
    public static final BitSet FOLLOW_NUMBER_in_factor173 = new BitSet(new long[]{0x0000000000000002L});

}